﻿using System;
using System.Collections;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;

public partial class WebUserControl_Baocaothongtinsanpham : System.Web.UI.UserControl
{
    BCDataCenter.DataAccessLayer.DAL dt;
    string error = "";
    static DataSet ds = new DataSet();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            try
            {
                ASPxPivotGrid1.DataSource = ds.Tables[0];
                ASPxPivotGrid1.DataBind();
            }
            catch (Exception ex)
            {
                BCDataCenter.ClassWriteLogErr obj = new BCDataCenter.ClassWriteLogErr();
                string method = System.Reflection.MethodBase.GetCurrentMethod().Name;
                obj.ErrorLog(ex.Message, method);
            }
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            dt = new BCDataCenter.DataAccessLayer.DAL();
            ds = dt.MyExecuteReader(ref error, "selectItemkey", CommandType.StoredProcedure);
            ASPxPivotGrid1.DataSource = ds.Tables[0];
            ASPxPivotGrid1.DataBind();
        }
        catch (Exception ex)
        {
            BCDataCenter.ClassWriteLogErr obj = new BCDataCenter.ClassWriteLogErr();
            string method = System.Reflection.MethodBase.GetCurrentMethod().Name;
            obj.ErrorLog(ex.Message, method);
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        try
        {
            using (MemoryStream filestream = new MemoryStream())
            {
                string contentType = "application/ms-excel";
                string fileName = "BaoCaothongtinsanpham.xls";
                ASPxPivotGridExporter1.ExportToXls(filestream);
                byte[] buffer = filestream.GetBuffer();
                Response.Clear();
                Response.Buffer = false;
                Response.AppendHeader("Content-Type", contentType);
                Response.AppendHeader("Content-Transfer-Encoding", "binary");
                Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileName);
                Response.BinaryWrite(buffer);
                Response.End();
            }
        }
        catch (Exception ex)
        {
            BCDataCenter.ClassWriteLogErr obj = new BCDataCenter.ClassWriteLogErr();
            string method = System.Reflection.MethodBase.GetCurrentMethod().Name;
            obj.ErrorLog(ex.Message, method);
        }
    }
}
